using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Zune.Forms
{
    /// <summary>
    /// General Drawing methods.
    /// </summary>
    public static class Drawing
    {
        /// <summary>
        /// Gets a Transparent Color.
        /// </summary>
        /// <returns>a Color.</returns>
        public static Color TransparentColor()
        {
            return new Color(0, 0, 0, 0);
        }

        /// <summary>
        /// Creates a Texture2D line.
        /// </summary>
        /// <param name="graphicsDevice">The GraphicsDevice.</param>
        /// <param name="x">The start x position.</param>
        /// <param name="y">The start y position.</param>
        /// <param name="x2">The end x position.</param>
        /// <param name="y2">The end y position.</param>
        /// <param name="color">The Color of the line.</param>
        /// <returns>A Texture2D line.</returns>
        public static Texture2D CreateLine(GraphicsDevice graphicsDevice, int x, int y, int x2, int y2, Color color)
        {
            return CreateRectangle(graphicsDevice, x + x2, y + y2, color);
        }

        /// <summary>
        /// Creates a color filled rectangle.
        /// </summary>
        /// <param name="graphicsDevice">The GraphicsDevice.</param>
        /// <param name="width">The width of the rectangle.</param>
        /// <param name="height">The height of the rectangle.</param>
        /// <param name="color">The Color of the rectangle.</param>
        /// <returns>A Texture2D rectangle.</returns>
        public static Texture2D CreateRectangle(GraphicsDevice graphicsDevice, int width, int height, Color color)
        {
            Texture2D rectangleTexture = new Texture2D(graphicsDevice, width, height, 1, TextureUsage.None, SurfaceFormat.Color);// create the rectangle texture, ,but it will have no color! lets fix that
            Color[] colors = new Color[width * height];//set the color to the amount of pixels

            for (int i = 0; i < colors.Length; i++)//loop through all the colors setting them to whatever values we want
            {
                colors[i] = color; //new Color(0, 0, 0, 255);
            }
            rectangleTexture.SetData(colors);//set the color data on the texture

            return rectangleTexture;
        }

        /// <summary>
        /// Draws a string twice using the two colors provided to simulate a drop shadow.
        /// </summary>
        /// <param name="spriteBatch">The SpriteBatch.</param>
        /// <param name="font">The SpriteFont.</param>
        /// <param name="value">The string to draw.</param>
        /// <param name="position">What Vector2 to draw at.</param>
        /// <param name="color">The main ForeColor</param>
        /// <param name="shadowColor">The shadow Color.</param>
        public static void DrawShadowedString(SpriteBatch spriteBatch, SpriteFont font, string value, Vector2 position, Color color, Color shadowColor)
        {
            spriteBatch.DrawString(font, value, position + new Vector2(1.0f, 1.0f), shadowColor);
            spriteBatch.DrawString(font, value, position, color);
        }

        /// <summary>
        /// Draws a border.
        /// </summary>
        /// <param name="spriteBatch">The SpriteBatch.</param>
        /// <param name="hLine">A Texture2D object that is the horizontal line to draw.</param>
        /// <param name="vLine">A Texture2D object that is the vertical line to draw.</param>
        /// <param name="location">A Vector2 position to draw the lines.</param>
        /// <param name="size">A Vector2 which is the size to draw the lines.</param>
        public static void DrawBorder(SpriteBatch spriteBatch, Texture2D hLine, Texture2D vLine, Vector2 location, Vector2 size)
        {
            spriteBatch.Draw(hLine, new Vector2(location.X, location.Y), Color.White);
            spriteBatch.Draw(hLine, new Vector2(location.X, location.Y + size.Y - hLine.Height), Color.White);
            spriteBatch.Draw(vLine, new Vector2(location.X, location.Y), Color.White);
            spriteBatch.Draw(vLine, new Vector2(location.X + size.X - vLine.Width, location.Y), Color.White);
        }

        /// <summary>
        /// Draws a border.
        /// </summary>
        /// <param name="spriteBatch">The SpriteBatch.</param>
        /// <param name="location">A Vector2 position to draw the lines.</param>
        /// <param name="size">A Vector2 which is the size to draw the lines.</param>
        /// <param name="borderColor">The Color of the border.</param>
        public static void DrawBorder(SpriteBatch spriteBatch, Vector2 location, Vector2 size, Color borderColor, int borderWidth)
        {
            Texture2D hLine = CreateLine(spriteBatch.GraphicsDevice, 0, 0, (Int32)size.X, borderWidth, borderColor);
            Texture2D vLine = CreateLine(spriteBatch.GraphicsDevice, 0, 0, borderWidth, (Int32)size.Y, borderColor);
            DrawBorder(spriteBatch, hLine, vLine, location, size);
        }

        /// <summary>
        /// Draws a 3D border (including drop shadow).
        /// </summary>
        /// <param name="spriteBatch">The SpriteBatch.</param>
        /// <param name="location">A Vector2 position to draw the lines.</param>
        /// <param name="size">A Vector2 which is the size to draw the lines.</param>
        /// <param name="borderColor">The Color of the border.</param>
        /// <param name="shadowColor">The Color of the drop shadow.</param>
        public static void Draw3DBorder(SpriteBatch spriteBatch, Vector2 location, Vector2 size, Color borderColor, Color shadowColor, int borderWidth)
        {
            Texture2D hLine = CreateLine(spriteBatch.GraphicsDevice, 0, 0, (Int32)size.X - 2, 1, borderColor);
            Texture2D vLine = CreateLine(spriteBatch.GraphicsDevice, 0, 0, 1, (Int32)size.Y - 2, borderColor);
            Texture2D hLine2 = CreateLine(spriteBatch.GraphicsDevice, 0, 0, (Int32)size.X - 2, 1, shadowColor);
            Texture2D vLine2 = CreateLine(spriteBatch.GraphicsDevice, 0, 0, 1, (Int32)size.Y - 2, shadowColor);

            spriteBatch.Draw(hLine2, new Vector2(location.X + 1, location.Y + size.Y - 2 - hLine2.Height + 1), Color.White);
            spriteBatch.Draw(hLine2, new Vector2(location.X + 2, location.Y + size.Y - 2 - hLine2.Height + 2), Color.White);
            
            spriteBatch.Draw(vLine2, new Vector2(location.X + size.X - 2 - vLine.Width + 1, location.Y + 1), Color.White);
            spriteBatch.Draw(vLine2, new Vector2(location.X + size.X - 2 - vLine.Width + 2, location.Y + 2), Color.White);

            DrawBorder(spriteBatch, hLine, vLine, location, new Vector2(size.X - 2, size.Y - 2));
        }
    }
}